﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="YUITreeList.aspx.cs" Inherits="ZX.WebApp.EditWidows.YUITreeList" %>

<%@ Register Assembly="ZX.Web.UI.Controls" Namespace="ZX.Web.UI.Controls" TagPrefix="cc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <!--CSS file (default YUI Sam Skin) -->


       <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/reset-fonts-grids/reset-fonts-grids.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/container/assets/skins/sam/container.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/menu/assets/skins/sam/menu.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/button/assets/skins/sam/button.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/resize/assets/skins/sam/resize.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/layout/assets/skins/sam/layout.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/datatable/assets/skins/sam/datatable.css" />
    <link rel="stylesheet" type="text/css" href="../Scripts/yui_2.9.0/build/paginator/assets/skins/sam/paginator.css" />
    <link rel="stylesheet" type="text/css" href="../scripts/yui_2.9.0/build/treeview/assets/skins/sam/treeview.css" />
    <!--begin custom header content for this example-->
    <style type="text/css">
    .yui-skin-sam table {
	    width: 100%;
    }
    #tree {background: #fff; padding:1em;}
    #button-example-form fieldset, 
    #button-example-form fieldset div {
        border: 2px groove #ccc;
        margin: .5em;
        padding: .5em;

    }
    .yui-button#pushbutton2 button,
    .yui-button#pushbutton5 button, 
    .yui-button#pushbutton4 button,
    .yui-button .Add button {
        background: url(../button/assets/add.gif) center center no-repeat;
        text-indent: -4em;
        overflow: hidden;
        padding: 0 .75em;
        width: 2em;
        *margin-left: 4em;   /* IE only */
        *padding: 0 1.75em;  /* IE only */
    }  
    .yui-button#pushbutton3 button,
    .yui-button#pushbutton6 button, 
    .yui-button#pushbutton9 button {
        padding-left: 2em;
        background: url(../button/assets/add.gif) 10% 50% no-repeat; 
    }
    <% =DataTableCss %>
</style>
    <!--end custom header content for this example-->
    <!-- Dependencies -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/element/element-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datasource/datasource-min.js"></script>
    <!-- OPTIONAL: JSON Utility (for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/json/json-min.js"></script>
    <!-- OPTIONAL: Connection Manager (enables XHR for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <!-- OPTIONAL: Get Utility (enables dynamic script nodes for DataSource) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/get/get-min.js"></script>
    <!-- OPTIONAL: Drag Drop (enables resizeable or reorderable columns) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/dragdrop/dragdrop-min.js"></script>
    <!-- OPTIONAL: Calendar (enables calendar editors) -->
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/calendar/calendar-min.js"></script>
    <script type="text/javascript" src="../Scripts/yui_2.9.0/build/datatable/datatable-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/layout/layout-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/button/button-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/container/container-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/treeview/treeview-min.js"></script>
    <script type="text/javascript" src="../scripts/yui_2.9.0/build/resize/resize-min.js"></script>
</head>
<body class="yui-skin-sam">
    <form id="form1" runat="server">
    <!-- 工具栏 -->
    <div id="listpage">
        <div id="toolbar" style="margin: 0px;">
        </div>
        <cc1:TreeView ID="treeDiv1" runat="server" TableName='SysFunction' Caption='Name'
            Key='FunctionID' ParentKey='ParentID' path='FunctionPath'></cc1:TreeView>
        <div id="data">
            <div id="top">
                <button type="button" id="btnAreaUserSet" name="btnAreaUserSet" >区域权限</button><% if (QuciklyQueryFields != string.Empty)
                                                  {  %><div style=" float:right;"><input id="QueryContext" type="text"/><button type="button" id="btnQuickQuery" name="btnQuickQuery" style="height:20px;" onclick="javascript:fnQuciklyQuery();">搜</button></div><%} %>
                    <% =BtnItems %>
                <button type="button" id="btnFull" name="btnFull">
                    全屏</button>
                <button type="button" id="btnReload" name="btnReload">
                        刷新</button>
                <button type="button" id="btnClose" name="btnClose">
                    关闭当前页</button>       
            </div>
            <div id="search" style="display:none">
                <select id="drpSearch">
                    <option selected="selected" value="CustomerName">客户名称</option>
                    <option value="Code">客户编码</option>
                </select>
                <input type="text" id="txtSearch" name="txtSearch" />
                <input type="button" id="btnSearch" name="btnSearch" value="查找" style="width:50px; text-align:center;" />
            </div>       
            <div id="json">
            </div>
        </div>
    </div>
    <div id="dialog1" class="yui-pe-content">
        <div class="hd">
            数据编辑</div>
        <div class="bd">
            <iframe id="EditUIWindow" frameborder="0" src="" style="width: 100%; height: 100%;
                margin: 0px; padding: 0px;"></iframe>
        </div>
    </div>

        <div id="dialog2" class="yui-pe-content">
        <div class="hd">
            数据编辑</div>
        <div class="bd">
            <iframe id="EditUIWindow1" frameborder="0" src="" style="width: 100%; height: 100%;
                margin: 0px; padding: 0px;"></iframe>
        </div>
    </div>
    </form>
</body>
<!-- 通用方法 -->
<script src="../Scripts/common.js" type="text/javascript"></script>
<!-- 定义数据格式化方法 -->
<script src="../Scripts/yui.list.dataformat.js" type="text/javascript"></script>
<!--  用于加载自定义脚本 -->
<script src="../Scripts/appjs/model.<% =EntityName %>.js" type="text/javascript" language="javascript"></script> 
<script type="text/javascript">
    var const_entityName="<%=EntityName%>"，
       const_QueryField="<% =QuciklyQueryFields %>";
    (function () {
        var Dom = YAHOO.util.Dom,
        Event = YAHOO.util.Event;
        Event.onDOMReady(function () {
            var layout = new YAHOO.widget.Layout({
                units: [
                { position: 'left', width: 200, body: 'treeDiv1', gutter: '0px 1px', collapse: true, scroll: true, zIndex: 1, resize: true },
                { position: 'center', body: 'data', minWidth: 400, minHeight: 200, scroll: true }

            ]
            });
            layout.render();
        });

		var tree1 = new YAHOO.widget.TreeView("treeDiv1");
		tree1.setNodesProperty('propagateHighlightUp',true);
		tree1.setNodesProperty('propagateHighlightDown',true);
		tree1.subscribe('clickEvent',tree1.onEventToggleHighlight);	
		tree1.render();
        BindData("00000000-0000-0000-0000-000000000000");
    })();
    
    var fkey="";
    function Native(caption,key){
      fkey=key;
      BindData(fkey);
      //condition=window.decodeURI("<%=ForeignKey%>='"+fkey+"'";
      //window.location.href='Extend/YUIList.aspx?entity=SysRole';
    }
    var _fn, _ids;
    var GetSelected=function(ids){
        _ids=ids
    }
   
    YAHOO.example.init = function () {
         function onButtonClick(p_oEvent) {
                 YAHOO.log("You clicked button: " + this.get("id"), "info", "example1");
                 switch(this.get("id"))
                 { 
                     <% =InitBtnEvents %>
                    case "btnFull": 
                         fnFull();
                         break;
                    case "btnClose":
                         fnAddMasterDetail();
                         //window.parent.$("#tabs").tabs('close','<% =PageTitle %>');
                         break;
                    case "btnReload":
                         fnReload();
                         break;
                    case "btnAreaUserSet":
                        fnAreaUserSet();
                        break;
                    default:

                         break;
                 }                        
        }
        YAHOO.util.Event.onContentReady("toolbar", function () {
        <% =BtnEvents  %>
          var btnAreaUserSet = new YAHOO.widget.Button("btnAreaUserSet");
            btnAreaUserSet.on("click", onButtonClick);
            var btns=document.getElementsByTagName("button");  
            if(const_entityName=="V_CrmCustomer"){
                document.getElementById("search").style.display="block";
                for(var i=0;i<btns.length;i++){
                   if(btns[i].id.indexOf("yui-gen")==-1){
                        btns[i].style.display="none";
                   }
                }
            }     
            if(const_entityName=="DatDepartment"){             
               for(var i=0;i<btns.length;i++){            
                   if(btns[i].id.indexOf("btnAreaUserSet")!=-1){
                        btns[i].style.display="block";
                   }
               }
            }
        var btnFull = new YAHOO.widget.Button("btnFull");
        btnFull.on("click", onButtonClick);
        var btnClose = new YAHOO.widget.Button("btnClose");
        btnClose.on("click", onButtonClick);
        var btnReload = new YAHOO.widget.Button("btnReload");
        btnReload.on("click", onButtonClick);
        });      
    } ();

    function AddButton() {
        var button = document.createElement('button');
        button.innerHTML = 'add tab';
        YAHOO.util.Event.on(button, 'click', addTab);
        tabView.appendChild(button);
    }


var mDataTable;
function BindData(fkey) {
    YAHOO.example.XHR_JSON = function() {
        var formatUrl = function(elCell, oRecord, oColumn, sData) {
            elCell.innerHTML = "<a href='" + oRecord.getData("ClickUrl") + "' target='_blank'>" + sData + "</a>";
        };      
        var formatRating = function(elCell, oRecord, oColumn, sData) {
            elCell.innerHTML = (sData === null) ? "N/A" : YAHOO.util.Number.format(sData);
        };
        var myColumnDefs = [
                <% =DataFields %>
        ];
        var myDataSource = new YAHOO.util.DataSource("../Extend/AjaxData/JSONList.aspx?");
        myDataSource.responseType = YAHOO.util.DataSource.TYPE_JSON;
        myDataSource.connXhrMode = "queueRequests";
        myDataSource.responseSchema = {
            resultsList: "rows",
            //fields: ["EntityName", "THCaption", "Field", { key: "Rating.AverageRating", parser: "number" }, "Width"]
            fields: [<% =DataColums %>]
        };
        this.myDataTable = new YAHOO.widget.DataTable("json", myColumnDefs,
                myDataSource, {initialRequest: "entity=<%=EntityName%>&order=<% =Order %>&zip=94089&results=10&output=json&r="+Math.random()+"&condition="+window.decodeURI("<%=ForeignKey%>='"+fkey+"'"),selectionMode:"single"  });
        mDataTable =this.myDataTable;
        var mySuccessHandler = function() {
            this.set("sortedBy", null);
            this.onDataReturnAppendRows.apply(this,arguments);
        };
        var myFailureHandler = function() {
            this.showTableMessage(YAHOO.widget.DataTable.MSG_ERROR, YAHOO.widget.DataTable.CLASS_ERROR);
            this.onDataReturnAppendRows.apply(this,arguments);
        };
        var callbackObj = {
            success : mySuccessHandler,
            failure : myFailureHandler,
            scope : myDataTable
        };
      
	    this.myDataTable.subscribe("rowMouseoverEvent", this.myDataTable.onEventHighlightRow); 
	    this.myDataTable.subscribe("rowMouseoutEvent", this.myDataTable.onEventUnhighlightRow); 
        this.myDataTable.subscribe("rowClickEvent", this.myDataTable.onEventSelectRow); 
        this.myDataTable.selectRow(this.myDataTable.getTrEl(0));    
        hideCol();
    }();
}
//隐藏/栏位
function hideCol(){ mDataTable.hideColumn(parseInt(0)); mDataTable.refreshView(); };
//YAHOO.util.Event.addListener(window, "load", BindData);
YAHOO.namespace("example.container");
 
YAHOO.util.Event.onDOMReady(function () {
	var handleSubmit = function() {
        var editwindow = document.getElementById("EditUIWindow");
        if(editwindow)
        {
           editwindow.contentWindow.Save();
        }
	}; 
	var handleCancel = function() {
		this.cancel();
	};
	var handleSuccess = function(o) {
		var response = o.responseText;
		response = response.split("<!")[0];
		document.getElementById("resp").innerHTML = response;
	};
	var handleFailure = function(o) {
		alert("Submission failed: " + o.status);
	};
    var handleCancel1= function() {
		        this.cancel();
	        };
    var callback =
        {
            success: handleSuccess1,
            failure: handleFailure1,
            argument: { foo: "foo", bar: "bar" }
        };
    var handleSubmit1 = function() {
      var editwindow1= document.getElementById("EditUIWindow1");
        if(editwindow1)
        {
           editwindow1.contentWindow.Save(fkey);
        }
            alert("设置成功");
            this.cancel();
	};
    var handleSuccess1 = function(o) {
	   alert("设置成功");
      this.cancel();
	};
	var handleFailure1 = function(o) {
        alert("操作失败");
	};
    // Remove progressively enhanced content class, just before creating the module
    YAHOO.util.Dom.removeClass("dialog1", "yui-pe-content");
	// Instantiate the Dialog
	YAHOO.example.container.dialog1 = new YAHOO.widget.Dialog("dialog1", 
							{ width : "450px",
                              height:"300px",
							  fixedcenter : true,
							  visible : false, 
							  constraintoviewport : true,
							  buttons : [ { text:"保存", handler:handleSubmit, isDefault:true },
								      { text:"取消", handler:handleCancel } ]
							});
    YAHOO.util.Dom.removeClass("dialog2", "yui-pe-content");
    YAHOO.example.container.dialog2= new YAHOO.widget.Dialog("dialog2", 
							{ width : "450px",
                              height:"360px",
							  fixedcenter : true,
							  visible : false, 
							  constraintoviewport : true,
							  buttons : [ { text:"保存", handler:handleSubmit1, isDefault:true },
								      { text:"取消", handler:handleCancel1 } ]
							});
	// Validate the entries in the form to require that both first and last name are entered
	YAHOO.example.container.dialog1.validate = function() {
		var data = this.getData();
		if (data.firstname == "" || data.lastname == "") {
			alert("Please enter your first and last names.");
			return false;
		} else {
			return true;
		}
	};
	YAHOO.example.container.dialog1.callback = { success: handleSuccess,
						     failure: handleFailure };
	YAHOO.example.container.dialog1.render();
    YAHOO.example.container.dialog2.render();
	YAHOO.util.Event.addListener("btnAddNew", "click", YAHOO.example.container.dialog1.show, YAHOO.example.container.dialog1, true);
    YAHOO.util.Event.addListener("btnAreaUserSet", "click", YAHOO.example.container.dialog2.show, YAHOO.example.container.dialog2, true);
	//YAHOO.util.Event.addListener("hide", "click", YAHOO.example.container.dialog1.hide, YAHOO.example.container.dialog1, true);
});
</script>
<script type="text/javascript" src="../Scripts/yui.list.YUITreeList.js"></script>
<script>
    YAHOO.util.Event.addListener(document, 'keydown', function (ev) {
        if (ev.ctrlKey && ev.keyCode == "72") {
            fnModuleHelp();
            //alert("帮助");
        }
        if (ev.ctrlKey && ev.keyCode == "83") {

            fnListSetting();
            //alert("设置");
        }
    });
</script>
</html>
